
*********************************************************************************;

/* 				This file produce ther results of Table 7 Panel B				*/
/*							Liquidity of funds trade							*/

*********************************************************************************;

libname rep "C:\Users\~";

data regbase; set rep.mydata; run;


%macro print;
data N; set N; Estimate = nValue1; if Label1 = "Used"; run;
data Nobs; set N; Parameter = "N"; keep EstType Parameter Estimate; run;
data r2; set fit; Parameter = "RSQ"; keep EstType Parameter RSquare; rename RSquare = Estimate;  run;
data final; set parest Nobs r2; drop EstType StdErr Probt DF; run;
data final&i; set final; rename Estimate = &liq._&type tValue = t_&liq._&type; 
if Parameter not in ("flow_all", "flow_low", "flow_high", "N", "RSQ") then delete; run;
%mend;


%macro all ;
%do j=1 %to 2;
%if &j =1 %then %do; %let liq = ba; %end; 
%else %do; %let liq = amihud; %end;
%do i=1 %to 2;
%if &i =1 %then %do; %let type = hf; %let flow = hfflow; %end; 
%else %do; %let type = mf; %let flow = active; %end;
%let yvar = &liq._&type;
ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=regbase plot =none;
endo &yvar ; exog &flow mktrf amihud tover hml smb ; instruments _exog_;
&yvar= flow_all*&flow  +b1*mktrf +b2*amihud +b3*tover + b4*hml +b5*smb +b0;
fit &yvar / gmm kernel=(bart,13,0) vardef=n; run; quit; 
%print;
%end;
data &liq; merge final1 final2; run;
%end;
data T7B_ttl; merge ba amihud; run;
%mend;

%macro decomp;
%do j=1 %to 2;
%if &j =1 %then %do; %let liq = ba; %end; 
%else %do; %let liq = amihud; %end;
%do i=1 %to 2;
%if &i =1 %then %do; %let type = hf; %let flow = hfflow; %end; 
%else %do; %let type = mf; %let flow = active; %end;
%let yvar = &liq._&type;
ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=regbase plot =none;
endo &yvar ; exog &flow._low &flow._high mktrf amihud tover hml smb ; instruments _exog_;
&yvar= flow_low*&flow._low + flow_high*&flow._high  +b1*mktrf +b2*amihud +b3*tover + b4*hml +b5*smb +b0;
fit &yvar / gmm kernel=(bart,13,0) vardef=n; run; quit; 
%print;
%end;
data &liq; merge final1 final2; run;
%end;
data T7B_freq; merge ba amihud; run;
%mend;

%all;
%decomp; 

proc print data = T7B_ttl noobs; run;
proc print data = T7B_freq noobs; run;
